#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
int search(vector<int>& nums, int target) {
    int left = 0;
    int right = nums.size() - 1;
    while (left <= right) {
        int mid = (left + right) / 2;
        if (nums[mid] == target) {
            return mid;
        }
        else if (nums[mid] > target) {
            right = mid - 1;
        }
        else {
            left = mid + 1;
        }
    }
    return -1;
}
vector<int> searchRange(vector<int>& nums, int target) {
    if (nums.size() == 0)
        return { -1, -1 };
    int left = 0;
    int begin = 0;
    int right = nums.size() - 1;
    while (left < right) {
        int mid = left + (right - left) / 2;
        if (nums[mid] < target) {
            left = mid + 1;
        }
        else {
            right = mid;
        }
    }
    if (nums[left] != target)
        return { -1, -1 };
    else
        begin = left;

    right = nums.size() - 1;
    while (left < right) {
        int mid = left + (right - left + 1) / 2;
        if (nums[mid] <= target)
            left = mid;
        else
            right = mid - 1;
    }
    return { begin, right };
}
int mySqrt(int x) {
    if (x < 1)
        return 0;
    int left = 1;
    int right = x;
    while (left < right) {
        long long mid = left + (right - left + 1) / 2;
        if (mid * mid <= x)
            left = mid;
        else
            right = mid - 1;
    }
    return left;
}
int searchInsert(vector<int>& nums, int target) {
    int left = 0;
    int right = nums.size() - 1;
    while (left < right) {
        int mid = left + (right - left) / 2;
        if (nums[mid] < target)
            left = mid + 1;
        else
            right = mid;
    }
    if (nums[left] < target)
        return right + 1;
    return right;
}
int peakIndexInMountainArray(vector<int>& arr) {
    int left = 0;
    int right = arr.size() - 2;
    while (left < right) {
        int mid = left + (right - left + 1) / 2;
        if (arr[mid] > arr[mid - 1])
            left = mid;
        else
            right = mid - 1;
    }
    return left;
}
int main()
{
    vector<int> nums = { 5,7,7,8,8,10 };
    int t = 8;
    vector<int> nums1 = searchRange(nums, t);
    for (int i = 0; i < nums1.size(); i++)
    {
        cout << nums1[i] << endl;
    }
    return 0;
}